package com.vonchenchen.mytest.PhotoRoll;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupWindow;

import com.vonchenchen.mytest.R;

/**
 * Created by Administrator on 2015/10/28 0028.
 */
public class PhotoRollPopWindow {

    private Context mCtx;

    private Bitmap mBitmap;
    private PopupWindow mPopupWindow;
    private View mBgView;

    private ImageView mCenterImage;

    public PhotoRollPopWindow(Context context, Bitmap bitmap){
        mBitmap = bitmap;
        mCtx = context;
        mBgView = View.inflate(mCtx, R.layout.popwindow_transparentblackbg, null);

        mCenterImage = (ImageView) mBgView.findViewById(R.id.iv_photo);

        mPopupWindow = new PopupWindow(mBgView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, false);

        mBgView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mPopupWindow.isShowing()){
                    mPopupWindow.dismiss();
                }
            }
        });
    }

    public void show(View rootView){
        if(rootView != null){
            mPopupWindow.setFocusable(true);
            mPopupWindow.showAtLocation(rootView, Gravity.NO_GRAVITY, 0, 0);

            mCenterImage.setImageBitmap(mBitmap);
        }
    }
}
